﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Admin/Views/Shared/MainContent.Master"
    Inherits="System.Web.Mvc.ViewPage<MShop.Core.Domain.WorkSpace>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    我的工作台
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <% var menu = ViewData["menus"] as IEnumerable<MShop.Core.Domain.Menu>;%>
    <% var menuids = (int[])ViewData["menuids"]; %>
    <% var workspaces = ViewData["workspaces2"] as IEnumerable<MShop.Core.Domain.WorkSpace>;%>
    <% var controller = ViewContext.Controller as MShop.Web.Areas.Admin.Controllers.SecureController;%>
    <% using (Html.BeginForm("Index", "WorkSpace", FormMethod.Post, new { id = "form1" }))
       {%>
    <div id="fullBox">
        <div class="tabListBoxHead">
            <div style="float: left; padding-top: 3px;">
                <img src="/Content/add.png" width="16" height="16" border="0" align="absmiddle" style="margin-right: 3px;" /> 
                我的工作台
            </div> 
        </div>
        <div class="tabListBox">
            <table id="ETList" style="text-align:center;"   cellpadding="0" cellspacing="0">
            <thead>
            <tr   >
            <th style="text-align:center;">
           所有菜单
            </th>
             <th>
           
            </th>
             <th style="text-align:center;">
           工作台菜单
            </th>
            </tr>
            </thead>
            <tbody>
                <tr>
                    <td>
                        <select name="sel1" id="sel1" multiple="multiple" style="width:150px;" size="20">
                            <% foreach (MShop.Core.Domain.Menu item in menu)
                               {
                                   if (item.CanView(controller.ShopContext.CurrentUser.ShopUserRights))
                                   {
                            %>
                            <!--<optgroup label='<%=item.Name%>'>
                    </optgroup>
                    -->
                            <% foreach (MShop.Core.Domain.Menu inneritem in item.Menu1)
                               {
                                   if (!menuids.Contains(inneritem.Id))
                                   {

                                       if (inneritem.CanView(controller.ShopContext.CurrentUser.ShopUserRights))
                                       { %>
                            <option value='<%=inneritem.Id %>'>
                                <%=inneritem.Name%></option>
                            <%}
                           }
                       }
                           }
                       } %>
                        </select>
                    </td>
                    <td >
                        <input type="button" id="b1" class="btn" value=" << " />
                        <input type="button" id="b2" class="btn" value=" < " />
                        <input type="button" id="b3" class="btn" value=" >> " />
                        <input type="button" id="b4" class="btn" value=" > " />
                        <input type="button" id="btnUp" class="btn" value=" 上 移 " />
                        <input type="button" id="btnDown" class="btn" value=" 下 移 " />
                    </td>
                    <td>
                        <select id="sel2"  name="sel2" style="width:150px;"  multiple="multiple" size="20">
                            <% foreach (MShop.Core.Domain.WorkSpace item in workspaces)
                               { %>
                            <option value='<%=item.MenuId %>'>
                                <%=item.Menu.Name%></option>
                            <% } %>
                        </select>
                    </td>
                </tr>
                <tr>
                <td colspan="3" align="center">
                 <input type="button" id="Submit1"  class="btn" value=" 取 消 " />
                  <input type="submit" id="mysubmit"  class="btn" value=" 保 存 " />
                </td>
                </tr>
                </tbody>
            </table>
            
        </div>
    </div>
    <%} %>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="cphMeta" runat="server">
    <script type="text/javascript" src="/js/jquery.validate-vsdoc.js"></script>
    <script type="text/javascript" src="/js/messages_cn.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#b1').click(function () {
                var sel = $('#sel2 option');
                for (var i = 0; i < sel.length; i++) {
                    $(sel[i]).attr("selected", false);
                    $(sel[i]).appendTo($('#sel1'));
                }
            });

            $('#b2').click(function () {
                var sel = $("#sel2 option:selected");
                for (i = 0; i < sel.length; i++) {
                    $(sel[i]).attr("selected", false);
                    $(sel[i]).appendTo("#sel1");
                }

            });

            $('#b3').click(function () {
                var sel = $("#sel1 option");
                for (i = 0; i < sel.length; i++) {
                    $(sel[i]).attr("selected", false);
                    $(sel[i]).appendTo("#sel2");
                }

            });


            $('#b4').click(function () {
                var sel = $("#sel1 option:selected");
                for (i = 0; i < sel.length; i++) {
                    $(sel[i]).attr("selected", false);
                    $(sel[i]).appendTo("#sel2");
                }

            });


            $('#btnUp').click(function () {
                var sel = $("#sel2 option:selected");
                var first = $("#sel2 option").first();
                if (sel.length == 1) {
                    $("#sel2 option").each(function (i) {
                        if ($(this).attr("selected")) {
                            if (i != 0) {
                                var prev = $("#sel2 option").get(i - 1);

                                var html = $(this).html();
                                var value = $(this).val();


                                $(this).html($(prev).html());
                                $(this).val($(prev).val());

                                $(prev).val(value);
                                $(prev).html(html);

                            }
                        }
                    });
                }
            });



            $('#btnDown').click(function () {
                var sel = $("#sel2 option:selected");
                var first = $("#sel2 option").first();
                if (sel.length == 1) {
                    $("#sel2 option").each(function (i) {
                        if ($(this).attr("selected")) {
                            if (i != $("#sel2 option").length - 1) {
                                var next = $("#sel2 option").get(i + 1);

                                var html = $(this).html();
                                var value = $(this).val();


                                $(this).html($(next).html());
                                $(this).val($(next).val());

                                $(next).val(value);
                                $(next).html(html);

                            }
                        }
                    });
                }
            });


            $('#mysubmit').submit(function () {
                $("#sel2 option").each(function (i) {
                    $(this).attr("selected", true);
                });
            });

            $('#form1').validate({
                rules: {
                    sel2: { required: true }             
                    },
                  messages: {
                        sel2: "你至少要选择一个菜单"
                }
            });

        });
    </script>


       <script type="text/javascript">
           $(document).ready(function () {
               var windowWidth = $("#fullBox").width();
               var windowHeight = $("#fullBox").height() - 30;
               $('.tabListBox').css({ 'width': windowWidth + 'px', 'height': windowHeight + 'px' });
               $(window).resize(function () {
                   var windowWidth = $("#fullBox").width();
                   var windowHeight = $("#fullBox").height() - 30;
                   $('.tabListBox').css({ 'width': windowWidth + 'px', 'height': windowHeight + 'px' });
               });
               $('.tabListBox').fixedHeaderTable({ footer: false, cloneHeaderToFooter: false, autoResize: true, fixCol1: true });

               $('.tabListBox').find("tbody").find("tr").each(function (i) {
                   if (i % 2 == 1) {
                       $(this).find("td").addClass("tr1");
                   }
               });
               $('.tabListBox').find("tbody").find("tr").mouseover(function (i) {
                   $(this).find("td").addClass("tr0");
               });
               $('.tabListBox').find("tbody").find("tr").mouseout(function (i) {
                   $(this).find("td").removeClass("tr0");
               });

           });
    </script>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="cphFooter" runat="server">
</asp:Content>
